//
//  SendViaSmsAction.m
//  NetEaseFinancial
//
//  Created by 吴玉峰 on 8/27/15.
//  Copyright (c) 2015 吴玉峰. All rights reserved.
//

#import "WYFSendViaSmsAction.h"

@interface WYFSendViaSmsAction ()<MFMessageComposeViewControllerDelegate>

@end

@implementation WYFSendViaSmsAction


- (NSString *)getIconName {
    return @"share_action_sms";
}

- (NSString *)getLabelName {
    return NSLocalizedString(@"短信\n", @"share_action_sms");
}

- (BOOL)shareWithHolder:(WYFShareHolder *)holder {
    [super shareWithHolder:holder];
    [self showMessageViewControllerWithholder:holder];

    return YES;
}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller
                 didFinishWithResult:(MessageComposeResult)result {
    switch (result) {
    case MessageComposeResultCancelled:
        NSLog(@"Cancelled");
        break;
    case MessageComposeResultFailed:
        NSLog(@"Failed");
        break;
    case MessageComposeResultSent:
        break;
    default:
        break;
    }
    [[UIApplication sharedApplication].windows[0].rootViewController dismissViewControllerAnimated:YES completion:nil];

}

- (void)showMessageViewControllerWithholder:(WYFShareHolder *)holder {
    if ([MFMessageComposeViewController canSendText]) {

        MFMessageComposeViewController *msgController = [[MFMessageComposeViewController alloc] init];
        // controller.recipients = @[@"10010", @"10086", @"10000"];
        msgController.body = [NSString stringWithFormat:@"%@ %@ %@",holder.title, holder.desc, holder.webUrl];
        msgController.messageComposeDelegate = self;

        [[UIApplication sharedApplication].windows[0].rootViewController presentViewController:msgController animated:YES completion:nil];

        [[[[msgController viewControllers] lastObject] navigationItem] setTitle:@"发送短信"]; //修改短信界面标题
    } else {

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"抱歉"
                                                        message:@"短信功能不可用!"
                                                       delegate:self
                                              cancelButtonTitle:@"好"
                                              otherButtonTitles:nil];
        [alert show];
    }
}

@end
